﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;

namespace BackupGUI
{
    using System.Collections;
    using System.Collections.ObjectModel;
    using System.IO;
    using System.Xml;
    using System.Xml.Serialization;
    using BackupLib;

    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class ProjectSettings : Window
    {
        private BackupProject Project { get; set; }

        public ProjectSettings()
        {
            InitializeComponent();
        }
        

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Project.AddTask(new BackupTask());
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            XML.Serialize(Project);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Project = XML.Deserialize();
            this.DataContext = Project;
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            Project.Tasks.RemoveAt(lstSource.SelectedIndex);
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            BackupTask task = lstSource.SelectedItem as BackupTask;

            var taskSettings = new TaskSettings();
            taskSettings.DataContext = task;
            taskSettings.ShowDialog();
        }

        private void btnBackup_Click(object sender, RoutedEventArgs e)
        {
            XML.Serialize(Project);
        }

        private void btnHide_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void lstSource_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            btnEdit_Click(null, null);
        }
    }
}
